// 提示信息仅在开发环境生效
import { createI18n } from "vue-i18n";
// import { store } from "@/store";

const files = import.meta.globEager("./modules/*.js");

const messages: any = {};

// let messages: LocaleMessages<VueMessageType> = {};
Object.keys(files).forEach((c: string) => {
  // @ts-ignore
  const module = files[c].default;
  const moduleName: string = c.replace(/^\.\/(.*)\/(.*)\.\w+$/, "$2");
  messages[moduleName] = module;
});
// const lang = store.state.app.lang || navigator.userLanguage || navigator.language // 初次进入，采用浏览器当前设置的语言，默认采用中文
const lang = (navigator.language || "en").toLocaleLowerCase(); // 初次进入，采用浏览器当前设置的语言，默认采用中文

// const locale = lang.indexOf("en") !== -1 ? "en" : "zh-cn";
const locale = localStorage.getItem("lang") || lang || "en";
// console.log(locale, "1");
// debugger;
// localStorage.getItem('lang') || language.split('-')[0] || 'en', // 首先从缓存里拿，没有的话就用浏览器语言，
const i18n = createI18n({
  __VUE_I18N_LEGACY_API__: false,
  __VUE_I18N_FULL_INSTALL__: false,
  globalInjection: true, //全局使用$t方法
  locale: locale,
  legacy: false,
  fallbackLocale: "zh-cn",
  silentTranslationWarn: true,
  missingWarn: false,
  silentFallbackWarn: true,
  fallbackWarn: false,
  messages
});
document.querySelector("html")!.setAttribute("lang", locale);

export default i18n;
